import java.util.Arrays;

public class Test {

    public static void main(String[] args) {
        char[] ch = new char[]{'a','b','c'};
        String s1 = new String(ch);

        s1.intern();
        String s2 = "abc";

        System.out.println("s1地址：0x" + Integer.toHexString(System.identityHashCode(s1)));
        System.out.println("s2地址：0x" + Integer.toHexString(System.identityHashCode(s2)));

        System.out.println(s1 == s2);
        // System.out.println(s1.equals(s2));
    }

    public static void main14(String[] args) {
        String str = "abcdef";

        // 从指定位置开始进行截取 知道截取到末尾
        // String ret = str.substring(2);
        // 截取[2,4)左闭右开的结构
        String ret = str.substring(2,4);
        System.out.println(ret);
    }

    public static void main13(String[] args) {
        String str = "  hello world  ";
        String ret = str.trim();
        System.out.println("["+str+"]");
        System.out.println("["+ret+"]");
    }

    public static void main12(String[] args) {
        String str = "hello world hello bit";
        // 按照空格分割 最多分割为2组
        String[] result = str.split(" ", 2);
        for(String s : result){
            System.out.println(s);
        }

        /*String str = "192\\168\\1\\1";
        String[] result = str.split("\\\\");
        for(String s : result){
            System.out.println(s);
        }*/

        // String str = "name=zhangsan&age=18";

        // String[] result = str.split("=|&");

        /*String[] result = str.split("&");

        for (int i = 0; i < result.length; i++){
            String[] temp = result[i].split("=");

            System.out.println(temp[0]+" = "+temp[1]);
        }*/
    }

    public static void main11(String[] args) {
        String str1 = "ababcabcdabcde";

        // String ret = str1.replace('a','k');
        // String ret = str1.replace("ab", "pl");
        // String ret = str1.replace("ab", "ok");
        // String ret = str1.replaceFirst("ab", "ok");
        String ret = str1.replaceAll("ab", "ok");

        /*String str2 = "kbkbckbcdkbcde";
        System.out.println(ret == str2);*/

        System.out.println(ret);
    }

    public static void main10(String[] args) {
        String s = String.format("%d-%d-%d", 2025,7,27);
        System.out.println(s);
    }

    public static void main9(String[] args) {
        String str = "abc";
        char[] chars = str.toCharArray();
        System.out.println(Arrays.toString(chars));

        String str2 = new String(chars);
        System.out.println(str2);
    }

    public static void main8(String[] args) {
        // 数字转字符串
        String s1 = String.valueOf(1234);
        String s2 = String.valueOf(12.34);
        String s3 = String.valueOf(true);
        String s4 = String.valueOf(new Student());

        System.out.println(s1);
        System.out.println(s2);
        System.out.println(s3);
        System.out.println(s4);

        System.out.println("=================================");
        // 字符串转数字
        // 注意：Integer、Double等是Java中的包装类型，这个后面会讲到

        int data1 = Integer.parseInt("1234");
        double data2 = Double.parseDouble("12.24");

        System.out.println(data1);
        System.out.println(data2);
    }

    public static void main7(String[] args) {
        String str1 = "ababcabcdabcde";

        // 从后往前找 默认是从最后一个位置开始找,给了fromindex之后,就是从指定位置开始往前找
        /*int index = str1.lastIndexOf("abc",8);
        System.out.println(index);*/

        // 字符串查找
        /*int index = str1.indexOf("abcd",2);
        System.out.println(index);*/

        /*int index = str1.indexOf('b',2);
        System.out.println(index);*/

        // 默认从0位置开始进行,查找到第一个就停止
        /*int index = str1.indexOf('b');
        System.out.println(index);*/

        char ch = str1.charAt(1);
        System.out.println(ch);
    }

    public static void main6(String[] args) {
        String str = "hello";
        String ret = str.toUpperCase();

        System.out.println(str);
        System.out.println(ret);

        String str2 = "WORLD";
        String ret2 = str2.toLowerCase();
        System.out.println(str2);
        System.out.println(ret2);
    }
    public static int worldLen(String str){
        String[] ret = str.split(" ");
        return ret[ret.length-1].length();
    }

    public static void main5(String[] args) {
        String str1 = "ABC";
        String str2 = "abc";
        System.out.println(str1.equalsIgnoreCase(str2));
    }

    public static void main4(String[] args) {
        String s1 = new String("abc");
        String s2 = new String("ac");
        String s3 = new String("abc");
        String s4 = new String("abcdef");
        System.out.println(s1.compareTo(s2));

        System.out.println(s1.compareTo(s3));

        System.out.println(s1.compareTo(s4));

    }

    public static void main3(String[] args) {
        String str1 = "hello";
        String str2 = "hello";
        System.out.println(str1 == str2);
        System.out.println(str1.equals(str2));
    }

    public static void main2(String[] args) {
        String str1 = "hello world";
        String str2 = "hello world";
        System.out.println(str1 == str2);
        System.out.println(str1);

        String str3 = new String("hello world");
        String str4 = new String("hello world");
        System.out.println(str3 == str4);
        System.out.println(str3);

        char[] array = {'h','e','l','l','o','w','o','r','l','d'};
        String str5 = new String(array);
        System.out.println(str5);
    }
    public static void main1(String[] args) {
        int ret = worldLen("helloworld");
        System.out.println(ret);
    }
}
